package com.lcifn.springmvc.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.lcifn.springmvc.bean.User;

@Controller
@SessionAttributes("user")
public class SessionController {
	
	ModelAndView mav = new ModelAndView("/WEB-INF/user/form.jsp");
	
	
	@RequestMapping("/session/index")
	public ModelAndView post(HttpSession session){
		mav.addObject("user", new User("zhangsan", 20));
		return mav;
	}

	@RequestMapping("/session/post")
	public ModelAndView post(@ModelAttribute("user") User user){
		System.out.println(user);
		return mav;
	}
	
	@RequestMapping("/session/get")
	public ModelAndView get(@SessionAttribute User user){
		System.out.println(user);
		mav.addObject("user", user);
		return mav;
	}
}
